import Vue from "vue";
import Vuex from "vuex";

//在Vue.js应用程序中使用Vuex进行状态管理，并从会话存储中移除了token和uid这两个项。
Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        token: sessionStorage.getItem('token'),
        uid: sessionStorage.getItem('uid')
    },
    mutations: {
        setToken(state, token) {
            state.token = token;
            sessionStorage.setItem('token', token);
        },
        setUid(state, uid) {
            state.uid = uid;
            sessionStorage.setItem('uid', uid);
        }
    },
    actions: {
        removeToken({ commit }) {
            commit('setToken', null);
            sessionStorage.removeItem('token');
        },
        removeUid({ commit }) {
            commit('setUid', null);
            sessionStorage.removeItem('uid');
        }
    }
});